<template>
	<view class="safety storesTransfer">

		<view class=" topHeaderBox between navBox" :style="{paddingTop: `${systemBarHeight+10}px`}">
			<uni-icons type="left" color="#fff" size="23" @click="goBack(100)"></uni-icons>
			<view>推广记录</view>
			<view style="font-size: 28rpx;" @click="onSkip(`/package/mine/invitation?pageType=推广记录`)">推广码</view>
			<view class="dataBox between">
				<view class="flex" style="justify-content: space-around;width: 70%;">
					<!-- 	<view class="flex-center" style="flex-direction: column;"
							@click="onSkip(`/package/mine/myBalance`)">
							<view>分红业绩(元)</view>
							<view class="dataVal">{{shareBonus}}</view>
						</view> -->
					<view class="flex-center" style="flex-direction: column;margin-left: 30rpx;"
						@click="onSkip(`/pages/tab/holdshares`)">
						<view>我的贡献值</view>
						<view class="dataVal">{{optionNum}}</view>
					</view>
					<view class="flex-center" style="flex-direction: column;margin-left: 30rpx;"
						@click="onSkip(`/pages/tab/holdshares`)">
						<view>推广总额</view>
						<view class="dataVal">{{totalmoney}}</view>
					</view>
				</view>
				<view class="btn flex-center" @click="onSkip(`/business/pages/business_tab/balanceWithdrawal?pageType=余额提现`)">
					提现
				</view>
			</view>
		</view>
		<!-- 主要内容区 -->
		<view class="mainBox" :style="{paddingTop:`${systemBarHeight+59}px`}">
			<!-- 筛选栏 -->
			<view class=" filterBigBox">
				<view class="tabs">
					<view class="tab_item" v-for="(item,i) in tabs" :key="item.val" @click="changeTabs(i)">
						<view class="tab_name" :class="{'tab_name_active':orderType==i}">{{item}}</view>
						<view class="tab_underline">
							<view class="active" v-if="orderType==i"></view>
						</view>
					</view>
				</view>
				<view class="flex-center timeEnd" @click="open('popup')">
					{{time}}
					<image class="downIcon" src="https://wx.2024csnl.com/static/mine/xiala.png"></image>
				</view>
			</view>
			<!-- 列表 -->
			<view style="padding-bottom: 100rpx;">
				<view class="oneList" v-for="(item,i) in list" :key="i">
					<view>
						<image :src="item.logo"></image>
					</view>
					<view class="rightBox">
						<view class="between">
							<view class="tit site">{{item.shop_name}}</view>
							<view style="color: #999;" v-if="item.status==0">未支付</view>
							<view style="color: #EC2E2F;" v-if="item.status==1||item.status==2">已支付</view>
						</view>
						<view>
							<text>支付金额：</text>{{item.totalprice}}
						</view>
						<view>
							<text>推广时间：</text>{{item.createtime}}
						</view>
						<view>
							<text>商家电话：</text>{{item.phone}}
						</view>
						<view class="site">
							<text>商家位置：</text>{{item.address}}
						</view>
					</view>
				</view>
			</view>
			<view class="flex-center addressImgBox" v-if="list.length==0">
				<image src="https://wx.2024csnl.com/static/noData.png"></image>
				暂无记录~
			</view>
			<view style="text-align: center;color: #999;" v-if="noMoreData&&list.length!=0">没有更多啦~</view>

			<uni-popup ref="popup" type="bottom">
				<u-calendar type="dateRange" :startYear="endYear-1" :endYear="endYear" @change="onChangeTime">
				</u-calendar>
			</uni-popup>
		</view>
	</view>
</template>

<script>
	import {
		getRecordPromotion
	} from "../../../api/index.js"
	export default {
		data() {
			return {
				list: [],
				totalPage: '',
				noMoreData: false,
				pagenum: 1,
				timeList: [],
				time: '时间',
				shareBonus: '', //分红
				optionNum: '', //贡献值
				endYear: new Date().getFullYear(),
				systemBarHeight: getApp().globalData.systemBarHeight,
				tabs: ['全部', '已支付', '未支付'],
				orderType: 0,
				totalmoney: "",
			}
		},
		onLoad() {
			this.onGetMsg()
		},
		onReachBottom() {
			if (this.pagenum < this.totalPage) {
				this.pagenum += 1
				this.onGetMsg('bottom')
			} else {
				this.noMoreData = true
			}
		},
		methods: {
			// 推广记录数据
			async onGetMsg(type) {
				const res = await getRecordPromotion(`s=/ApiZwyRequest/pluglog`, {
					starttime: this.timeList[0]?.result,
					endtime: this.timeList[1]?.result,
					status: this.orderType == 0 ? 'all' : this.orderType == 1 ? 1 : 0,
					pagenum: this.pagenum
				})
				const {
					status,
					msg,
					fenhon,
					totalmoney,
					option_num,
					data
				} = res.data
				if (status == 1) {
					this.totalmoney = totalmoney
					this.shareBonus = fenhon
					this.optionNum = option_num
					this.totalPage = data.last_page
					type == 'bottom' ? this.list.push(...data.data) : this.list = data.data
					this.pagenum != 1 && data.data.length == 0 ? this.noMoreData = true : this.noMoreData = false
					// console.log(res, 'oooo')
				} else {
					this.showToast(msg)
				}
			},

			onChangeTime(e) {
				// console.log(e, "eee")
				this.timeList = e
				this.time = this.timeList[1].result
				this.pagenum = 1
				this.onGetMsg()
				setTimeout(() => {
					this.close('popup')
				}, 100)

			},
			open(n) {
				this.$refs[n].open();
			},
			close(n) {
				this.$refs[n].close();
			},
			changeTabs(i) {
				this.orderType = i
				this.timeList = []
				this.time = '时间'
				this.pagenum = 1
				this.onGetMsg()
			},

		}
	}
</script>

<style>
	page {
		background: #F7F7F7;
	}
</style>
<style lang="scss" scoped>
	.addressImgBox {
		flex-direction: column;
		color: #999;
		padding-top: 20%;

		image {
			width: 400rpx;
			height: 400rpx;
		}
	}

	.oneList {
		padding: 40rpx 30rpx;
		background: #fff;
		display: grid;
		grid-template-columns: 25% 75%;
		grid-gap: 0 20rpx;
		margin-bottom: 20rpx;

		image {
			width: 180rpx;
			height: 180rpx;
			border-radius: 10rpx;
		}

		.rightBox {
			padding: 0 30rpx 0 15rpx;
			font-size: 30rpx;
			line-height: 48rpx;

			.tit {
				width: 65%;
				font-weight: bold;
				color: #333333;
				font-size: 32rpx;
				margin-bottom: 30rpx;
			}

			.site {
				white-space: nowrap;
				text-overflow: ellipsis;
				overflow: hidden;
			}

			text {
				color: #999999;
			}
		}
	}

	.filterBigBox {
		z-index: 0;
		background: #fff;
		display: grid;
		grid-template-columns: 70% 30%;
		margin-bottom: 10rpx;

	}

	.downIcon {
		z-index: 0;
		width: 24rpx;
		height: 16rpx;
		margin-left: 15rpx;
	}

	.mainBox {
		// #ifdef H5
		margin-top: 15vh;
		// #endif
		// #ifdef APP-PLUS
		padding-top: 15vh;
		// #endif
	}

	.tabs {
		width: 100%;
		display: flex;
		justify-content: space-between;
		padding: 36upx 30upx 17upx;
		box-sizing: border-box;
		background-color: #fff;

		.tab_item {
			.tab_name {
				font-size: 30upx;
				color: #999999;
				line-height: 30upx;

				margin-bottom: 14upx;
			}

			.tab_name_active {
				color: #F17816;
				font-weight: bold;
			}

			.tab_underline {
				display: flex;
				justify-content: center;

				>view {
					width: 40upx;
					height: 6upx;
					border-radius: 2upx;
				}

				.active {
					background-color: #F17816;

				}
			}
		}
	}

	.dataBox {
		align-items: center;
		color: #B3B3B3;
		font-size: 26rpx;
		position: absolute;
		font-weight: 500;
		top: 8.5vh;
		// #ifdef APP-PLUS
		top: 9.5vh;
		// #endif
		width: 84vw;
		background: #fff;
		border-radius: 30rpx;
		padding: 30rpx;

		.dataVal {
			font-size: 32rpx;
			color: #FF9320;
			margin-top: 15rpx;
			font-weight: bold;
		}

		.btn {
			padding: 0 40rpx;
			height: 64rpx;
			background: #EC2E2F;
			border-radius: 40rpx;
			font-size: 32rpx;
			color: #fff;
			// font-weight: bold;
		}
	}

	.storesTransfer {
		background: #F7F7F7;
		min-height: 100vh;
	}

	.topHeaderBox {
		// #ifdef APP-PLUS
		padding: 30rpx;
		height: 270rpx;
		// #endif
		// #ifdef H5
		padding: 30rpx;
		height: 300rpx;
		// #endif
		position: fixed;
		left: 0;
		right: 0;
		top: 0;
		z-index: 999;
		display: flex;
		background: linear-gradient(0deg, #FFA025, #41644A);
	}

	.navBox {
		font-size: 34rpx;
		font-weight: bold;
		color: #fff;
	}
</style>